package com.hit.client.comm.service;

import cn.hutool.core.util.IdUtil;
import com.hit.client.api.dto.config.RobotBaseProperties;
import com.hit.client.api.dto.service.Send2ServerService;
import com.hit.client.comm.ChannelCache;
import com.hit.client.comm.NettyClient;
import com.hit.comm.dto.CommWrapperDTO;
import com.hit.comm.dto.RegisterInfoReq;
import com.hit.comm.type.CommTypeEnum;
import com.hit.comm.utils.ProtostuffUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author kehanjiang
 * @date 2025/04/21
 */
@Service
@Slf4j
@AllArgsConstructor
public class Send2ServerServiceImpl implements Send2ServerService {

    @Override
    public boolean registerClient(RobotBaseProperties baseInfo) {
        NettyClient.getInstance().connect(baseInfo.getServerIpAddr(), baseInfo.getServerTcpPort());
        return true;
    }

    @Override
    public boolean requestServerData() {
        Long serialNumber = IdUtil.getSnowflakeNextId();
        ChannelCache.send2All(new CommWrapperDTO(CommTypeEnum.TYPE_10001.getCode(), null, serialNumber));
        return true;
    }
}